﻿using System;
using System.Text;
using System.Collections.Generic;
using WebApiCoreDemo.Model;

namespace WebApiCoreDemo.Common
{
    public class IPUtil
    {
        /// <summary>
        /// 获取访问者的真实IP
        /// </summary>
        /// <returns></returns>
        public static string GetVisitorRealIP()
        {
            #region 获取Nginx/客户端的IP地址
            //string realIP = "";
            //if (string.Equals(Appsettings.DeployType, "NginxCluster", StringComparison.OrdinalIgnoreCase))
            //{
            //    if (!string.IsNullOrEmpty(MyHttpContext.Current.Request.Headers["X-Real-IP"]))
            //    {
            //        realIP = MyHttpContext.Current.Request.Headers["X-Real-IP"];
            //    }
            //    else
            //    {
            //        realIP = MyHttpContext.Current.Connection.RemoteIpAddress.ToString();
            //    }
            //}
            //else
            //{
            //    realIP = MyHttpContext.Current.Connection.RemoteIpAddress.ToString();
            //} 
            #endregion
            return MyHttpContext.Current.Connection.RemoteIpAddress.ToString();
        }
    }
}
